package LeetCode.tree;

import java.util.Scanner;

public class NC {  // 二叉树04 第一题
    public static void main(String[] args) {
        main1();
    }
    public static TreeNode main1() {
        NC nc = new NC();
        Scanner in = new Scanner(System.in);
            String s = in.nextLine();
            TreeNode root = nc.createTree(s);
            nc.middle(root);
            return root;
    }
    int i = 0;
    public TreeNode createTree(String s){
        TreeNode root = null;
        if(s.charAt(i) != '#'){
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = createTree(s);
            root.right = createTree(s);
        } else {
            i++;
        }
        return root;
    }
    public void middle(TreeNode root){
        if(root == null){
            return;
        }
        middle(root.left);
        System.out.print(root.val + " ");
        middle(root.right);
    }
}
